home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / RESOURCES / KOOB / main.cs < prev    next >
Text File  |  2006-09-25  |  7KB  |  169 lines

  1. $traceMode = false;
  2. $winConsole = false;
  3.  
  4. trace($traceMode);//leave this as is,change $traceMode above to true/false instead.
  5. EnableWinConsole($winConsole); // leave alone, change $winConsole instead.
  6. // send logging output to a windows console window
  7. //------------------------------------------------------------------------
  8. //  ./main.cs   v0.3
  9. //
  10. //  root main module for 3D2E Koob23 sample game
  11. //
  12. //  Copyright (c) 2003,2006 by Kenneth C.  Finney.
  13. //------------------------------------------------------------------------
  14.  
  15. // ========================================================================
  16. // ========================= Initializations ==============================
  17. // ========================================================================
  18.  
  19. $usageFlag =  false;  //help won't be displayed unless the command line
  20.                       //switch ( -h ) is used
  21.  
  22. $logModeEnabled =  true; //track the logging state we set in the next line.
  23. SetLogMode(6);   // overwrites existing logfile & closes log file at exit.
  24. ///**NOTE log mode changed from book version in order to track & preserve errors
  25. /// from debug sesssions
  26.  
  27. // ========================================================================
  28. // ======================= Function Definitions ===========================
  29. // ========================================================================
  30.  
  31. function OnExit()
  32. //------------------------------------------------------------------------
  33. // This is called from the common code modules. Any last gasp exit
  34. // acticities we might want to perform can be put in this function.
  35. // We need to provide a stub to prevent warnings in the log file.
  36. //------------------------------------------------------------------------
  37. {
  38. }
  39.  
  40. function OnStart()
  41. //------------------------------------------------------------------------
  42. // This is called from the common code modules. Any last initial
  43. // acticvities we might want to perform can be put in this function.
  44. // We need to provide a stub to prevent warnings in the log file.
  45. //------------------------------------------------------------------------
  46. {
  47. }
  48.  
  49. function ParseArgs()
  50. //------------------------------------------------------------------------
  51. //  handle the command line arguments
  52. //
  53. //  this function is called from the common code
  54. // NOTE: some variables used in the function are globals (use the $)
  55. // because we need their values that are set inside this function to 
  56. // also be accessible outside this function as well.
  57. //------------------------------------------------------------------------
  58. {
  59.   for(%i = 1; %i  < $Game::argc ; %i++) //loop thru all command line args
  60.   {
  61.     %currentarg    = $Game::argv[%i];   // get current arg from the list
  62.     %nextArgument       = $Game::argv[%i+1]; // get arg after the current one
  63.     %nextArgExists = $Game::argc-%i > 1;// if there *is* a next arg,note that
  64.     $logModeEnabled =  false;           // turn this off-let the args dictate
  65.                                 // if logging should be enabled.
  66.  
  67.     switch$(%currentarg)
  68.     {      
  69.         case "-dedicated":
  70.         $Server::Dedicated = true;
  71.         EnableWinConsole(true);
  72.         $argumentFlag[%i]++;
  73.  
  74.       case "-map":
  75.         $argumentFlag[%i]++;
  76.         if (%nextArgExists)
  77.         {
  78.            $mapArgument = %nextArgument;
  79.            $argumentFlag[%i+1]++;
  80.            %i++;
  81.         }
  82.         else
  83.            Error("Error: Missing argument. Usage: -mission <filename>");
  84.  
  85.       case "-?":       // the user wants command line help, so this cause the
  86.         $usageFlag = true;   // Usage function to be run, instead of the game
  87.         $argumentFlag[%i] = true;                // adjust the argument count
  88.  
  89.       case "-h":         // exactly the same as "-?"
  90.         $usageFlag = true;
  91.         $argumentFlag[%i] = true;
  92.     }
  93.   }
  94. }
  95.  
  96. function Usage()
  97. //------------------------------------------------------------------------
  98. // Display the command line usage help
  99. //------------------------------------------------------------------------
  100. {
  101. //  NOTE: any logging entries are written to the file 'console.log'
  102.   Echo("\n\nKoob23 command line options:\n\n" @
  103.          " -h, -?              display this message\n" );
  104. }
  105.  
  106. function  LoadAddOns(%list)
  107. //------------------------------------------------------------------------
  108. // Exec each of the startup scripts for add-ons.
  109. //------------------------------------------------------------------------
  110. {
  111.   if (%list $= "")
  112.     return;
  113.   %list = NextToken(%list, token, ";");
  114.   LoadAddOns(%list);
  115.   Exec(%token @  "/main.cs");
  116. }
  117.  
  118. // ========================================================================
  119. // ================ Module Body - Inline Statements =======================
  120. // ========================================================================
  121. //  Parse the command line  arguments
  122. ParseArgs();
  123.  
  124. //  Either  display the help message or start the program.
  125. if  ($usageFlag)
  126. {
  127.   %saveWinConsole = $winConsole;
  128.   EnableWinConsole(false);// send logging output to a windows console window
  129.   Usage();
  130.   EnableWinConsole(%saveWinConsole);//restore windows console mode
  131.   Quit();
  132. }
  133. else
  134. {
  135.   //  scan argument list, and log an Error message for each unused argument
  136.   // NOTE that the $i is used, not %i. This code is NOT in a function - it is inline,
  137.   // so we need to use the $ (global scope) and not the % (local scope).
  138.   for ($i = 1;  $i  < $Game::argc; $i++)
  139.   {
  140.      if (!$argumentFlag[$i])
  141.         Error("Error: Unknown command line argument:  " @ $Game::argv[$i]);
  142.   }
  143.  
  144.   if  (!$logModeEnabled)
  145.   {
  146.      SetLogMode(6);      //  Default to  a new logfile each session.
  147.   }
  148.   //  Set the add-on path list to specify the directories that will be
  149.   //  available to the scripts and engine. note that *all* required
  150.   //  directory trees are included: common and control as well as the
  151.   //  user add-ons.
  152.   $pathList = $addonList !$= "" ? $addonList @ ";control;common" : "control;common";
  153.   SetModPaths($pathList);
  154.   $addonList="control;creator";
  155.  
  156.   // Execute startup script for the common code modules
  157.   Exec("common/main.cs");
  158.  
  159.   // Execute startup script for the control specific code modules
  160.   Exec("control/main.cs");
  161.  
  162.   // Execute startup scripts for all user add-ons
  163.   Echo("--------- Loading Add-ons ---------");
  164.   LoadAddOns($addonList);
  165.   Echo("Engine initialization complete.");
  166.  
  167.   OnStart();
  168. }
  169.